

<form class="form-horizontal" id="ae_form" action="/pg/ac_Rilevazioni/ImportCsvUpdate" method=POST enctype=multipart/form-data role="form">
    <fieldset>
<div class="form-group">
    <label class="col-sm-2 col-lg-2 control-label" for="id_ente" >Seleziona un Ente da inserire/modificare</label>
    <div class="col-sm-5 col-lg-5">
        <select id="id_ente" name="id_ente" class="validate[required]">
<!--
            <option value=""></option>
-->
            {% for t in pageData['enti'] %}
                <option value="{{t.id}}" {{ 'selected="selected"' if t.id == pageData["dao"].id_ente}}  >{{t.denominazione}} </option>
            {% endfor %}
        </select>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-2 col-lg-2 control-label" for="id_categoria" >Seleziona una Categoria da inserire/modificare</label>
    <div class="col-sm-5 col-lg-5">
        <select id="id_categoria" name="id_categoria" class="validate[required]">
        </select>
    </div>
</div>
    <div class="form-group">
        <label class="col-sm-2 col-lg-2 control-label" for="separatore" >Separatore campi</label>
        <div class="col-sm-5 col-lg-5">
            <select id="separatore" name="separatore" class="">
                <option value=";"> ; </option>
                <option value=":"> : </option>
                <option value=","> , </option>
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 col-lg-2 control-label" for="delimitatore" >Delimitatore stringa</label>
        <div class="col-sm-5 col-lg-5">
            <select id="delimitatore" name="delimitatore" class="">
                <option value='"'> " </option>
                <option value="'"> ' </option>
                <option value=" ">  </option>
            </select>
        </div>
    </div>
        <div class="form-group">
        <label class="col-sm-2 col-lg-2 control-label" for="jumprow" >Numero righe da saltare</label>
        <div class="col-sm-5 col-lg-5">
            <select id="jumprow" name="jumprow" class="">
                <option value='0'> 0 </option>
                <option value="1"> 1 </option>
                <option value='2'> 2 </option>
                <option value="3"> 3 </option>
                <option value='4'> 4 </option>
                <option value="5"> 5 </option>
                <option value='6'> 6 </option>
                <option value="7"> 7 </option>
                <option value='8'> 8 </option>
                <option value="9"> 9 </option>
                <option value='10'> 10 </option>
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 col-lg-2 control-label" for="inputCSV">File CSV da importare</label>
    <div class="col-sm-5 col-lg-5">
        <div class="fileinput fileinput-new" data-provides="fileinput">
            <span class="btn btn-default btn-file">
                <span class="fileinput-new">Seleziona un file</span>
                <span class="fileinput-exists">Cambia</span>
                    <input type="file" id="inputCSV" name="inputCSV">
            </span>
                <span class="fileinput-filename"></span>
            <a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">&times;</a>
        </div>
        <p class="help-block">Selezionare il file CSV specifico per questa categoria</p>
    </div>
    </div>

<div class="form-group" title="Bottoni di salvataggio e reset del form">
        <div class="col-sm-5 col-lg-5 col-sm-offset-2">
            <input class="btn btn-info" type="submit" value="Salva" name="add"/>
            <input class="btn btn-warning" type="submit" value="Cancella" name="add"/>
<!--
            <input class="btn btn-default" type="button" value="Chiudi" name="chiudi" id="chiudi_edit"/>
-->
        </div>
    </div>
</div>

</fieldset>
</form>
<script>
  $(document).ready(function(){

$( "#ae_form" ).validationEngine({
                    prettySelect : true,
                    useSuffix: "_chosen",
                });

$( "#id_ente" ).chosen({ width: "50%", allow_single_deselect: true}).change(function (e) {
    var id_ente = $("#id_ente").find("option:selected").val();
    {% if pageData["dao"].id_categoria %}
        var id_categoria_edit = {{pageData["dao"].id_categoria}}
    {% else %}
        var id_categoria_edit = false
    {% endif %}

    if (id_categoria_edit!==false){
        options = '<option value="' + id_categoria_edit + '">' + '{{pageData["dao"].categoria}}' + '</option>';
         $("#id_categoria").html(options);
         $("#id_categoria").trigger("chosen:updated");
    } else {
       $.getJSON("/pg/ac_Rilevazioni/GetCate",{id_ente:id_ente}, function(data){
        var options = "<option value="+"></option>"
         $.each( data, function( k, v ){
           options += '<option value="' + v.id + '">' + v.denominazione + '</option>';
         });
         $("#id_categoria").html(options);
         $("#id_categoria").trigger("chosen:updated");
         //$( "#id_categoria" ).trigger( "change" )

        });
    }
});

$( "#id_ente" ).trigger( "change" )
$("#id_categoria").chosen({ width: "50%",
                allow_single_deselect: true})

});

</script>
